<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>呼叫楼长</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="applicable-device" content="mobile">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=yes, width=device-width">
	<meta name="format-detection" content="telephone=no" />
  	<link rel="stylesheet" href="css/ui-selectbox.css">
	<link rel="stylesheet" href="css/style.css">
	<script src="js/jquery.js"></script>
    <script src="js/common.js"></script>
    <script src="js/selectbox-min.js"></script>
    <script>
    //展示学校
    $.ajax('./fycaption', {   
        dataType: 'text', 
        type: 'post',
        success: function(data) {  
        	var obj = eval(data);
        	$("#sel-school").empty(); 
        	var option = $("<option selected>").val("").text("请选择学校校区（必选）"); 
        	$("#sel-school").append(option); 
        	$.each(obj,function(n,value){
        		option = $("<option>").val(value.shname).text(value.shname); 
            	$("#sel-school").append(option); 
        		}
        	);
        	
        }  
      });
    $(document).ready(function(){  
	　　　　$('#sel-school').change(function(){  
			 if($(this).children('option:selected').val() == ""){
				 $("#sel-school1").empty(); 
				 var option = $("<option>").val("").text("请选择校区（必选）"); 
		        	$("#sel-school1").append(option); 
			 }else{
				 var shname=encodeURI(encodeURI($(this).children('option:selected').val()));//这就是selected的值  
				 //根据选择学校展示校区
				     $.ajax('./fycaptionArea?shname='+shname, {   
				        dataType: 'text', 
				        type: 'post',
				        success: function(data) {  
				        	var obj = eval(data);
				        	$("#sel-school1").empty(); 
				        	//alert(data);
				        	var option = $("<option>").val("").text("请选择校区（必选）"); 
				        	$("#sel-school1").append(option); 
				        	$.each(obj,function(n,value){
					        		if(value.sharea == ""){
					        			//alert(1);
					        			$("#area").hide(); 
					        			//校区不存在，通过校名直接搜索
					        			$("#areahidden").val("无"); 
										$.ajax('./fycaptionBuilding?shname='+shname, {   
									        dataType: 'text', 
									        type: 'post',
									        success: function(data) {  
									        	var obj = eval(data);
									        	//alert(obj);
									        	$("#sel-school2").empty(); 
									        	var option = $("<option>").val("").text("请选择楼（必选）"); 
									        	$("#sel-school2").append(option); 
									        	$.each(obj,function(n,value){
									        		option = $("<option>").val(value.bdname).text(value.bdname); 
									            	$("#sel-school2").append(option); 
									        		}
									        	);
									        }  
									      });
					        			$('#building').show();
					        			
					        		}else{
					        			$("#areahidden").val(""); 
					        			$("#sel-school1").removeAttr("disabled"); 
					        			option = $("<option>").val(value.sharea).text(value.sharea); 
						            	$("#sel-school1").append(option); 
					        		}
				        		}
				        	);
				        	
				        }  
				      });
			 }
	　　　　}) 
	    
	    $('#sel-school1').change(function(){  
				 if($(this).find("option:selected").val()== ""){
					 $('#building').hide();
				 }else{
					 var sharea=encodeURI(encodeURI($(this).find("option:selected").val()));//这就是selected的值  
					 //根据选择学校展示校区
					     $.ajax('./fycaptionBuilding?sharea='+sharea, {   
					        dataType: 'text', 
					        type: 'post',
					        success: function(data) {  
					        	var obj = eval(data);
					        	//alert(obj);
					        	$("#sel-school2").empty(); 
					        	var option = $("<option>").val("").text("请选择楼（必选）"); 
					        	$("#sel-school2").append(option); 
					        	$.each(obj,function(n,value){
					        		option = $("<option>").val(value.bdname).text(value.bdname); 
					            	$("#sel-school2").append(option); 
					        		}
					        	);
					        	
					        }  
					      });
					 $('#building').show();
				 }
		　　　});
	});
    
    function checkCaption(){
    	var school = encodeURI(encodeURI($("#sel-school").find("option:selected").val()));
    	var area = encodeURI(encodeURI($("#area").find("option:selected").val()));
    	var building = encodeURI(encodeURI($("#building").find("option:selected").val()));
    	
    	if($("#areahidden").val() == "无" ){
    		
    		area = encodeURI(encodeURI($("#areahidden").val()));
    	}
    	
    	if($("#sel-school").find("option:selected").val()!="" && area!="" && $("#building").find("option:selected").val()!=""){
    		window.location.href="./fycaptionCall?school="+school+"&area="+area+"&building="+building;
    	}else{
    		alert("请选择所有选项");
    	}
    }		 
    </script>
</head>
<body>
    <div class="page">

        <header class="base-header">
          <a href="javascript:history.go(-1);" class="btn-back posa">返回</a>
        </header>
	<input type="hidden" id="areahidden" name="areahidden" value=""/>

        <div class="login-form login-form-bgWhite">
          <!-- <div class="login-raw"><input type="text" placeholder="请输入设备号"></div>-->
          <div class="login-raw">
            <select id="sel-school">
              <option value="">请选择学校校区（必选）</option>
            </select>
          </div>
          <div class="login-raw" id="area" >
            <select id="sel-school1">
              <option value="">请选择校区（必选）</option>
            </select>
          </div>
          <div class="login-raw" id="building" >
            <select id="sel-school2">
              <option value="">请选择大楼（必选）</option>
            </select>
          </div>

          <div class="tc btn-bottom"><a href="#" onclick="checkCaption();" class="btn">确认提交</a></div>
          <div class="tc"><a href="signup.html" class="link-goSignUp">认证Young粉获得更好体验</a></div>
        </div>
        
    </div>
    <script>
      $(function(){
        // 下拉
        $('select').each(function () {
          selectbox(this);
        });
        

      })
    </script>

    <!--百度数据统计-->
    <script>var _hmt = _hmt || [];(function() {var hm = document.createElement("script");hm.src="https://hm.baidu.com/hm.js24866553cf6bdd25afcd437091f96447";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s);})();</script>

</body>
</html>
















